﻿<EditDataFormTemplateSpec 
	xmlns="bb_appfx_editdataformtemplate"
	xmlns:common="bb_appfx_commontypes" 
	ID="9ac1de50-d362-48c2-a865-4467b3a641a2" 
	Name="Prospect Edit Data Form"
	Description="Edit Prospect record" 
	Author="Blackbaud Professional Services"
	DataFormInstanceID="79595955-a43e-4407-be69-02ec6989636f" 
	RecordType="Prospect"
	common:SecurityUIFolder="Service Bus Adapter"
	>

  <SPDataForm>

    <!-- define the edit load SP, which is used to load the data for the form -->
    <LoadImplementation SPName="USP_DATAFORMTEMPLATE_EDITLOAD_PROSPECT_CUSTOM">
      <common:CreateProcedureSQL>
        <![CDATA[
create procedure dbo.USP_DATAFORMTEMPLATE_EDITLOAD_PROSPECT_CUSTOM(
  @ID uniqueidentifier,
  @DATALOADED bit = 0 output,
  @TSLONG bigint = 0 output,
  @DateFrom datetime = null output,
  @DateTo datetime = null output
  
)
as

	set nocount on;

	-- be sure to set these, in case the select returns no rows
	set @DATALOADED = 0
	set @TSLONG = 0

	-- populate the output parameters, which correspond to fields on the form.  Note that
	-- we set @DATALOADED = 1 to indicate that the load was successful.  Otherwise, the system
	-- will display a "no data loaded" message.  Also note that we fetch the TSLONG so that concurrency
	-- can be considered.
	select
		@DATALOADED = 1,
		@TSLONG = TSLONG	from dbo.PROSPECT
	where ID = @ID

	return 0;
				]]>
      </common:CreateProcedureSQL>
    </LoadImplementation>

    <SaveImplementation SPName="USP_DATAFORMTEMPLATE_EDIT_PROSPECT_CUSTOM">
      <common:CreateProcedureSQL>
        <![CDATA[
create procedure dbo.USP_DATAFORMTEMPLATE_EDIT_PROSPECT_CUSTOM (
@ID uniqueidentifier,
--@FundraiserId uniqueidentifier,
@DateFrom datetime,
@DateTo datetime


)
as

	set nocount on;

DECLARE @CHANGEAGENTID uniqueidentifier

	if @CHANGEAGENTID is null  
		exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output
				
	declare @CURRENTDATE datetime
	set @CURRENTDATE = getdate()


	begin try
    
    UPDATE PROSPECT 
    SET
    PROSPECTMANAGERSTARTDATE = @DateFrom,
    PROSPECTMANAGERENDDATE = @DateTo

    WHERE ID = @ID


	end try
	begin catch
		exec dbo.USP_RAISE_ERROR
		return 1
	end catch

return 0;
				]]>
      </common:CreateProcedureSQL>
    </SaveImplementation>

  </SPDataForm>

  <!-- describe fields on the form, which correspond to parameters on the SP.  Note that system paramters 
	like the record ID, DATALOADED, TSLONG, and CURRENTAPPUSERID need not be listed. -->
  <common:FormMetaData FixedDialog="true">
    <common:FormFields>
      <common:FormField FieldID="DateFrom" Caption="Date From" DataType="Date" />
      <common:FormField FieldID="DateTo" Caption="Date To" DataType="Date" />      

    </common:FormFields>

  </common:FormMetaData>

</EditDataFormTemplateSpec>